﻿
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
namespace sharpxbot.Utils.Database
{
    public class SQLiteDatabase : IDatabase
    {
        public SQLiteDatabase()
        {
            conn = new SQLiteConnection();
        }

        #region IDatabase Members

        public void Connect(string connectionString)
        {
            conn.ConnectionString = connectionString;
            conn.Open();
        }

        public void Disconnet()
        {
            conn.Close();
        }

        public ConnectionState State
        {
            get
            {
                return conn.State;
            }
        }

        public DbCommand CreateCommand(string cmdText)
        {
            return new SQLiteCommand(cmdText, conn);
        }

        public object CreateCommandParameter(string paramName, object value)
        {
            SQLiteParameter result = new SQLiteParameter()
            {
                ParameterName = paramName,
                Value = value
            };

            return result;
        }

        #endregion

        public void Foo()
        {
            SQLiteCommand cmd = new SQLiteCommand("select text from verses", conn);
            SQLiteDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                string txt = reader.GetString(0);
            }
        }

        #region Private fields

        private SQLiteConnection conn;

        #endregion
    }
}
